﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentSystem
{
    class StudentSystem
    {
        static void Main()
        {

            Student Pesho = new Student("Petyr", "Ivanov", 21);
            Student Vankata = new Student("Ivan", "Petrov", 22);
            Student Mimi = new Student("Maria", "Georgieva", 20);
            Student Doncho = new Student("Doncho", "Minkov", 50);
            Student James = new Student("James", "Hetfield", 33);

            Student[] studList = { Pesho, Vankata, Mimi, Doncho, James };

            foreach (Student student in studList)
            {
                Console.WriteLine("{0} {1}, age: {2}", student.FirstName, student.LastName, student.Age);
            }
            Console.WriteLine();
            Console.WriteLine("students with first name before last name alphabetically are: ");
            Console.WriteLine();

            var students =
                from student in studList
                where student.FirstName.CompareTo(student.LastName) < 0
                select student;

            foreach (Student student in students)
            {
                Console.WriteLine(student.FirstName + " " + student.LastName);
            }

            Console.WriteLine();
            Console.WriteLine("students with age between 18 and 24 are: ");
            Console.WriteLine();

            var filteredAgeStudents =
                from student in studList
                where ((student.Age >= 18) && (student.Age <= 24))
                select student;
            foreach (Student student in filteredAgeStudents)
            {
                Console.WriteLine("{0} {1}, age: {2}", student.FirstName, student.LastName, student.Age);
            }

            Console.WriteLine();
            Console.WriteLine("sorted students: ");
            Console.WriteLine();

            var sortedStudents =
                from student in studList
                orderby student.FirstName descending, student.LastName descending
                select student;
            foreach (var student in sortedStudents)
            {
                Console.WriteLine("{0} {1}, age: {2}", student.FirstName, student.LastName, student.Age);
            }

        }
    }
}
